package com.ysd.lis.service.impl;

import com.ysd.common.Result;
import com.ysd.lis.mapper.TDictionaryLocalMapper;
import com.ysd.lis.request.DictionaryLocalListAddParam;
import com.ysd.lis.service.TDictionaryLocalService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @description:
 * @author: JG
 * @time: 2021/11/29 10:22
 */

@Service
@Slf4j
public class TDictionaryLocalServiceImpl implements TDictionaryLocalService {

    @Resource
    TDictionaryLocalMapper tDictionaryLocalMapper;

    @Override
    public Result findDictionaryLocalByKeyList(String macAddress){
        try {
            List<DictionaryLocalListAddParam> dictList = tDictionaryLocalMapper.findDictionaryLocalByKeyList(macAddress);
            Map<String, Object> data = new HashMap<>();
            data.put("dictList",dictList);
            return Result.succ(1,"查询成功",data);
        } catch (Exception e) {
            log.error("findDictionaryLocalByKeyList err {} ",e);
            return Result.fail("查询异常");
        }

    }

    @Override
    public Result addDictionaryLocalList(List<DictionaryLocalListAddParam> params){
        try {
            //删除原数据
            String orgId = params.get(0).getOrgId();
            String userId = params.get(0).getUserId();
            tDictionaryLocalMapper.deleteDictionaryLocalByOrgId(orgId,userId);
            //保存
            tDictionaryLocalMapper.addDictionaryLocalList(params);
            return Result.succ(1,"保存成功",null);
        } catch (Exception e) {
            log.error("addDictionaryLocalList err {}",e);
            return Result.fail("保存异常");
        }

    }
}
